﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lwm.x10c.Intermediate.Instructions
{
    public enum CompareOp
    {
        Equal = 2, NotEqual = 3,
        Greater = 4, Less = 5,
        GreaterEqual = 6, LessEqual = 7
    }

    public enum CompareOpDump
    {
        jeq = 2, jne = 3,
        jg = 4, jl = 5,
        jge = 6, gle = 7
    }

    public class CondJumpInsn : JumpInsn
    {
        private static string[] symbols = new string[] {
            "", "", "==", "!=", ">", "<", ">=", "<="
        };

        public override string NiceName { get { return Enum.GetName(typeof(CompareOp), this.Operator); } }
        public override string DumpName { get { return Enum.GetName(typeof(CompareOpDump), (CompareOpDump)this.Operator); } }
        public override bool Op1Used { get { return true; } }
        public override bool Op2Used { get { return true; } }

        public CompareOp Operator { get; set; }

        public override void Dump(StringBuilder sb)
        {
            sb.Append(this.DumpName + " ");
            this.Op1.Dump(sb);
            sb.Append(" " + symbols[(int)this.Operator] + " ");
            this.Op2.Dump(sb);
            sb.Append(", " + this.Target.Name);
        }
    }
}
